import { MES_LXK_ApiHost } from '@/utils/Interceptors'

// 定义数据类型
export interface DefectItemSummary {
  summaryId: number
  workOrderId: number
  workOrderNumber: string
  productId: number
  productNumber: string
  productName: string
  productSpecification: string
  workProcessId: number
  workProcessNumber: string
  workProcessName: string
  reportingId: number
  reportingQuantity: number
  goodQuantity: number
  defectQuantity: number
  productionWorker: string
  defectItemId: number
  defectItemName: string
  productionStartTime: string
  productionEndTime: string
  plannedQuantity: number
  isDelete: boolean
}

export interface ApiResponse {
  code: number
  msg: string
  data: DefectItemSummary[]
}

export interface SearchParams {
  startTime?: string
  endTime?: string
  workOrderNumber?: string
  productName?: string
  defectItemName?: string
}

// 获取所有不良品项汇总数据
export const getAllSummaries = async (params?: SearchParams) => {
  return await MES_LXK_ApiHost.get<ApiResponse>('/api/DefectItemSummary/GetAllDefectItemSummaries', { params })
}

// 根据条件搜索不良品项汇总数据
export const searchSummaries = async (params: SearchParams) => {
  return await MES_LXK_ApiHost.get<ApiResponse>('/api/DefectItemSummary/GetAllDefectItemSummaries', { params })
}

// 导出不良品项汇总数据
export const exportSummaries = async (params?: SearchParams) => {
  return await MES_LXK_ApiHost.get('/api/DefectItemSummary/ExportDefectItemSummaries', { 
    params,
    responseType: 'blob',
    headers: {
      'Accept': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel, */*'
    }
  })
}
